package com.gbits.app.finance.convert;

import java.util.List;
import java.util.Map;

import com.gbits.app.finance.api.DebitItemConvert;
import com.gbits.app.finance.domain.CostOrgSubjectMapper;
import com.gbits.app.finance.domain.DeptSubjectMapper;
import com.gbits.app.finance.domain.Subject;

/**
 * 默认科目转换
 * @author wangqt
 *
 */
public class DebitSubjectConvert extends DebitItemConvert {

	@Override
	public String getUsageInfo(Map<String, Object> map) {
		return this.getUsage(map);
	}

	@Override
	public String getSubjectDetail(Map<String, Object> map) {
		String splitStr = SUBJECT_SPLIT;
		String orgCode = this.getCompanyCode(map);
		String costOrgName = this.getCostOrgName(map);
		CostOrgSubjectMapper cosm = this.getCostOrgSubjectMapperService().get(orgCode, this.getCostOrgName(map));
		
		String subjectCode = cosm.getSubjectCode();
		List<Subject> subjects = this.getSubjectService().getSubjectsDetail(subjectCode, this.getSubjectName(map), orgCode);
		
		StringBuffer sb = new StringBuffer();
		sb.append(subjects.get(subjects.size() - 1).getCode());
		sb.append(splitStr);
		for (int i=0; i<subjects.size(); i++) {
			if (i > 0) {
				sb.append(splitStr);
			}
			Subject s = subjects.get(i);
			sb.append(s.getName());
		}
		DeptSubjectMapper deptDsm = this.getDeptSubjectMapperService().getDeptSubject(costOrgName, orgCode);
		DeptSubjectMapper proDsm = this.getDeptSubjectMapperService().getProductSubject(costOrgName, orgCode);
		// 部门核算
		sb.append("/");
		sb.append(deptDsm.getJdCode());
		sb.append(splitStr);
		sb.append(deptDsm.getJdFullName());
		
		// 产品核算
		sb.append("/");
		sb.append(proDsm.getJdProductCode());
		sb.append("-");
		sb.append(deptDsm.getJdProductName());
		return sb.toString();
	}
	
	@Override
	public String getDebitAmount(Map<String, Object> map) {
		if (this.isCantainTax(map)) {
			return this.getNoTaxAmount(map);
		}
		return this.getAmount(map);
	}

}
